<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>可选的线段绘制</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
    canvas {
      outline: none;
    }
    .buttons {
      position: absolute;
      top: 50px;
      left: 50%;
      transform: translateX(-50%);
      font-size: 14px;
    }
  </style>
</head>
<body>
  <script type="x-shader/x-vertex" id="vertexshader">
    attribute float visible;
    varying float vVisible;
    attribute vec3 vertColor;
    varying vec3 vColor;

    void main() {
      vColor = vertColor;
      vVisible = visible;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
    }
  </script>
  <script type="x-shader/x-fragment" id="fragmentshader">
    varying float vVisible;
    varying vec3 vColor;

    void main() {
      if (vVisible > 0.0) {
        gl_FragColor = vec4(vColor, 1.0);
      } else {
        discard;
      }
    }
  </script>

  <div class="buttons">
    <button id="hide">隐藏</button>
    <button id="show">显示</button>
  </div>

  <script src="./_selective_draw.js" type="module"></script>
</body>
</html>